package com.itzyf.pokemondata.fragment

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.itzyf.pokemondata.R
import com.itzyf.pokemondata.activity.panel.PanelDetailActivity
import com.tydic.baselibrary.fragment.BaseFragment

private const val ARG_PARAM1 = "IMAGE"

/**
 * @author 依风听雨
 * @version 创建时间：2019/04/30 08:49
 */
class ImageFragment : BaseFragment() {

    private var imageUrl: String? = ""

    override fun initView(view: View?) {
        view?.let {
            val icon = view.findViewById<ImageView>(R.id.icon)
            Glide.with(this).load(imageUrl).into(icon)
            icon.setOnLongClickListener {
                (mActivity as PanelDetailActivity).saveImage()
                return@setOnLongClickListener true
            }
        }


    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            imageUrl = it.getString(ARG_PARAM1)
        }
    }

    override fun getLayoutID() = R.layout.fragment_image


    companion object {

        @JvmStatic
        fun newInstance(imageUrl: String) =
            ImageFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, imageUrl)
                }
            }
    }

}